package bhbt.utils;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import bhbt.model.Admin;
import bhbt.model.Member;






public class ContextUtil {
	private static ApplicationContext context;

	public static ApplicationContext getContext() {
		return context;
	}

	public static void setContext(ApplicationContext ctx) {
		context = ctx;
	}
	
	public static <T> T getBean(String beanId) {
		return (T)getContext().getBean(beanId);
	}

	public static HttpServletRequest getRequest(){
		ServletRequestAttributes attr = (ServletRequestAttributes)
				RequestContextHolder.currentRequestAttributes();
		HttpServletRequest request = attr.getRequest();
		return request;
	}
	
	
	
	/**
	 * 获取member session状态
	 * @return
	 */
	public static Member getMember() {
		HttpSession session = getRequest().getSession();
		return (Member)session.getAttribute(SysConst.MEMBER);
	}

	/**
	 * 获取admin session状态
	 * @return
	 */
	public static Admin getAdmin() {
		HttpSession session = getRequest().getSession();
		return (Admin)session.getAttribute(SysConst.MG);
	}

	
}
